from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import HttpResponse, redirect


class AuthMiddleware(MiddlewareMixin):

    def process_request(self, request):
        # 如果有info信息
        info_dict = request.session.get("info")
        if info_dict:
            return
        #   request.path_info 获取当前用户请求的URL /reply/
        if request.path_info in ["reply"]:
            # 2.没有登录过，重新回到登录页面
            return redirect('/login/')
        return
